<div id="email_in_ildds" class="easyui-layout tab_a" fit="true">
    <div data-options="region:'center',border:false">
        <table id="email_in_list"></table>
        <div id="emailinboxtoolbar" style="padding:5px;height:auto">
            <div>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="readEmalInbox()">标记为已读</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="del_email_list('in')">删除</a>
                <label style=" float:right;" >
                    	<input id="email_in_search_key" class="email_in_search_form textbox" style="width:200px;" type="text">
                    	<a href="#" class="easyui-linkbutton email_in_search_form" plain="true"  iconCls="icon-search" onclick="advanced_search('email_in','email_in_search_key')">搜索</a>
                    <a id="email_in_advancedSearch" href="javascript:void(0)" class="easyui-linkbutton" plain="true" onclick="advanced_search('email_in','高级')">高级</a>
                    
                </label>
            </div>
        </div>
	</div>
</div>
<script>

//收件箱数据构造方法，包括列表属性设置，字段设置，双击设置
$('#email_in_list').datagrid({
    url:'<?php echo base_url('email/getinboxlistdata');?>',
	method:'post',
	singleSelect:true,
	selectOnCheck:false,
	pagination:true,
	pageSize:30,
	pageList:[30,50,100],
	fit:true,
	fitColumns:true,
	border:false,
	queryParams:{},
	sortName:'bodyid',
	sortOrder:'desc',
	toolbar:'#emailinboxtoolbar',	
    columns:[[
		{field:'id',checkbox:true},
		{field:'isread',title:'未读',width:7,align:'center',
			formatter: function(value,row,index){
				if(value == 0){
					return "<div class='icon-email_new' style='height: 16px;'></div>";
				}
			}
		},
		{field:'important',title:'',width:5,align:'center',
			formatter: function(value,row,index){
				if(value != 0){
					return "<div style='color:#ff0000;'>急！</div>";	
				}
			}
		},
        {field:'sender',title:'发件人',width:16,align:'center'},
        {field:'title',title:'标题',width:200},
		{field:'isattach',title:'附件',width:10,align:'center',
			formatter: function(value,row,index){
				if(value != '' || value != 0){
					return "<div class='icon-attach' style='height: 16px;'></div>";
				}
			}
		},
        {field:'sendertime',title:'发送时间',width:30,align:'center',sortable:'true',
			formatter: function(value,row,index){
				//return getLocalTime(value);
				return value;
			}
		}
    ]],
	onDblClickRow:function(index,data){
		//var row=$('#email_in_list').datagrid('getSelected');
		//alert(row.title);
		//if(row){/**当前的tab 是否存在如果存在就 自动选择 否则 创建新的tab**/
		
			//var title = 'ES'+row.id+':'+SetString(row.title,16);
			//var title = (data.title)'ES'+row.id+':'+SetString(data.title,16);
			var title = (strlen(data.title) >10)?SetString(data.title,10)+'..':data.title;//如果标题超过10个字符，则截取10个字符加..
			var es_id = 'es_'+data.id; //拼接面板ID
			var es_obj = $('#main-tab').find("#"+es_id);//获取面板ID对象对象
			//alert(es_obj.length);
			
			if (es_obj.length>0){ //如果存在
				var tab_index = es_obj.parent().index();//检查该对象的父元素在其父元素中的索引
				$('#main-tab').tabs('select', tab_index); //选择该索引对应的面板
			} else {
				/**添加一个tab标签**/
				$("#main-tab").tabs('add',{
					id: es_id,
					title: '收件箱：'+title,
					href: '<?php echo base_url();?>email/contentbox/in/'+data.id,
					tabWidth:'160',
					selected: true,
					closable:true,
					onLoad:function(){
						//为面板添加详细标题属性 
						var item1 = $('.tabs-selected').find("span:first");
						$('#main-tab').find(item1).attr("title",data.title);
						
						//刷新收件箱列表
						//$('#email_in_list').datagrid('reload');			
						
						//打开成功后，删除列表中的新邮件图标
						$('#email_in_list').datagrid('updateRow',{
							index: index,
							row: {
								isread: 1
							}
						});	
					}
				});
			}
		//}
	},
	onLoadSuccess:function(){		
        var pager = $(this).datagrid('getPager');
        pager.pagination({
            displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录'
        });
    }

});

//"设为已读"函数
function readEmalInbox(){
	var getobj = $('#email_in_list').datagrid("getChecked");
	var getid = [];
		$.each(getobj, function(index, item){
			getid.push(item.id);
		}); 
	if(getid.length == 0){
		$.messager.alert('错误','要设为已读，请选取要操作的行','error');
	}else{            
		$.post("<?php echo base_url('email/setread');?>",{getid:getid},function(result){
			if(result.success){
				$('#email_in_list').datagrid('reload');
			}else{
				$.messager.alert('错误',result.errorMsg,'error');
			}
		},'json');
	}
}
</script>